﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class DeleteUser : System.Web.UI.Page
{
    private string userName;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Session["userName"]!=null)
        {
            userName=Session["userName"].ToString();
            if(!IsPostBack)
            {
            BindUsers();
            }
        }
        else
        {
            Response.Redirect(GetUrlPath.GetUrl + "/Login.aspx");

        }

    }
    //删除用户的方法
    protected void btnDelUser_Click(object sender, EventArgs e)
    {
        int isSaveMsg =Convert.ToInt32(radioBtnDel.SelectedValue);
        if (Users.DeleteUser(Convert.ToString( ddlUsers.SelectedItem), isSaveMsg))
        {
            Response.Write("<script language='javascript'>alert('删除成功！')</script>");
            BindUsers();
        }
        else
        {
            Response.Write("<script language='javascript'>alert('删除失败！')</script>");
        }


    }
    //读取系统所有用户，并绑定到页面的下拉列表
    protected void BindUsers()
    {
        string searchUsers = "select * from USERS where USERNAME<>'"+userName+"'";
        string tableName = "userName";
        DBOperation db = new DBOperation();
        DataSet ds = db.GetDataSet(searchUsers,tableName);
        ddlUsers.DataSource = ds.Tables["userName"];
        ddlUsers.DataTextField ="USERNAME";
        ddlUsers.DataBind();
    }
}
